/*
** 提供最基础的功能
*/

//协议
var HTTP_PROTOCOL = location.href.indexOf('https') > -1 ? 'https:' : 'http:';

(function (win) {

    var methods = {
        //等待时机执行
        //conditionAction：检测时机是否成熟
        //doAction：时机成熟时执行的操作
        //time：轮询时间，默认100ms
        //调用示例：pageInitBase.waitDo(()=>window.$,()=>console.log('jquery loaded'));
        waitDo: function (conditionAction, doAction, time) {
            if (!conditionAction || !doAction) {
                return;
            }
            if (!time) {
                time = 100;
            }
            if (conditionAction()) {
                doAction();
            } else {
                var timer = setInterval(function () {
                    if (conditionAction()) {
                        clearInterval(timer);
                        doAction();
                    }
                }, time);
                setTimeout(() => clearInterval(timer), 5000);

            }

        },
        //加载js
        loadScript: function (src, CB) {
            var script = document.createElement('script');
            script.onload = function () {
                if (CB) CB();
            };
            script.src = src;
            document.getElementsByTagName('head')[0].appendChild(script);
            return script;
        },

    };

    win.pageInitBase = methods;

})(window);
